<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Button;
use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\components\Edit;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;
use think\facade\View;

class Express extends Base
{
    public function getOptions(): array
    {
        return [
            'pk' => 'id',
            'model' => \app\common\model\Express::class,
            'validate' => \app\admin\validate\Express::class
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['title', '物流公司', null, fn(Edit $e) => $e->require()],
                ['code', '物流编码', null, fn(Edit $e) => $e->text()],
                ['status', '状态', fn(Column $col) => $col->switch('开启|关闭', '1|0')],
                ['sort', '排序', fn(Column $col) => $col->fastSort(), fn(Edit $e) => $e->number()],
                ['create_time', '添加时间', fn(Column $col) => $col->width(150)],
                ['update_time', '更新时间', fn(Column $col) => $col->width(150)]
            ])
            ->addTopButtons([
                'add',
                'deleteAll',
                'checkView' => fn(Button $btn) => $btn->title('查看编码')
                    ->icon('layui-icon-search')
                    ->class('warm')
                    ->url(url('list')->build())
                    ->customEvent('checkView')
            ])
            ->addRightButtons(['edit', 'delete'])
            ->addSearch([
                ['title', '物流公司', fn(Search $search) => $search->condition('Like')]
            ])
            ->enableExport()
            ->fetch();
    }

    public function list(): string
    {
        View::assign('list', []);

        return View::fetch();
    }
}